package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.MemberIsSelectAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;

/**
* @Description: TODO
*
* @author lyx
* @date 2020年11月27日
* @version V1.0
* @Package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler
*/
@Service
@AttrHandler(MemberIsSelectAttrHandler.class)
public class MemberIsSelectAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData>{

    @Autowired
    OperateInstAttrService operateInstAttrService;
    
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 套包不选用时，清空同组的属性值（不可编辑通过配置处理）
        if (KiteStringUtils.equals(attr.getValue(), "100006443")) {
            inst.getAttrMap().forEach((key, value) -> {
                if (KiteStringUtils.equals(attr.getGroupId(), value.getGroupId())
                    && !KiteStringUtils.equals(value.getFieldName(), attr.getFieldName())) {
                    operateInstAttrService.setAttrValue(inst, value.getFieldName(), "", data.getSceneInstId(), "");
                }
            });
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {
        
    }

}
